package Towary;

public class Towar {
        
        public int id=0;
        private int waga=0;
        boolean gotowy=false;
        
        public Towar(int id){
                this.id=id;             
        }
        
        public synchronized int podajWage(){
                try {
                        while(gotowy==false){
                                wait();
                        }
                } catch (InterruptedException e) {
                        e.printStackTrace();
                }
                //////////
                /*  System.out.println(Thread.currentThread().getName() + " wczytuje wage produktu " + id + " = "+ waga);
                try {
                        Thread.currentThread().sleep(10);
                } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }*/
                //////////
                gotowy = false;
                notifyAll();
                return this.waga; 
        }
        
        public synchronized void zapiszWage(int waga){
                this.waga=waga;
                while(gotowy==true) {
                        try {
                                wait();
                        } catch (InterruptedException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                }
                //////////
                /*System.out.println(Thread.currentThread().getName() + " zapisuje wage produktu " + id + " = "+ waga);
                try {
                        Thread.currentThread().sleep(10);
                } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }*/
                //////////
                gotowy=true;
                notifyAll();
        }
        
        
}